#include <iostream>
#include <string>
#include <stack>

using namespace std;

class Solution
{
public:
   bool isValid(string s) {
	    if(s=="")
		   return false;

		stack<char> st;
		st.push(s[0]);

		for(int i=2;i<=s.length();++i)
		{
			char c=s[i-1];
			if(c=='{'||c=='('||c=='[')
			{
				st.push(c);
				continue;
			}
			else
			{
				if(st.empty())
					return false;

				char top=st.top();
				st.pop();
				if((top=='{'&&c=='}')
					||(top=='['&&c==']')
					||(top=='('&&c==')'))
					continue;
				else
					return false;
			}
		}

		return st.empty();
	}
};

int main()
{
	Solution solution;
	string s="[])";
	cout<<solution.isValid(s)<<endl;
}